package com.ai.tikai.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

import java.util.stream.Stream;

public enum AuditLabel {
    SPAM("spam", "垃圾内容"),
    PORN("porn", "色情"),
    ABUSE("abuse", "辱骂"),
    TERRORISM("terrorism", "暴恐"),
    AD("ad", "广告");

    private final String value;
    private final String description;

    AuditLabel(String value, String description) {
        this.value = value;
        this.description = description;
    }
    // Jackson会使用这个方法来从JSON字符串创建枚举实例
    @JsonCreator
    public static AuditLabel fromValue(String value) {
        if (value == null) {
            return null;
        }
        // 关键：将传入的字符串转为小写，再进行匹配
        return Stream.of(AuditLabel.values())
                .filter(c -> c.value.equalsIgnoreCase(value)) // 使用忽略大小写的比较
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("Unknown enum type " + value + ", Allowed values are " + Stream.of(values()).map(e -> e.value).toList()));
    }
    // 序列化为小写字符串，如 "spam"
//    @JsonValue
//    public String getValue() {
//        return value;
//    }

    public String getDescription() {
        return description;
    }
}
